package com.llyb.chap08;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ScheduledAtFixRateDemo {

    public static void main(String[] args) {
        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(3);

        try {
            for (int i = 0; i < 2; i++) {
                scheduledExecutorService.schedule(()->{
                    System.out.println(Thread.currentThread().getName()+"\t"+"---- come in");
                    try {
                        TimeUnit.SECONDS.sleep(2);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                },5, TimeUnit.SECONDS);

            }
        } finally {
            scheduledExecutorService.shutdown();
        }
    }
}
